//
//  ZLImpressTableViewCell.m
//  TripTogether
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 杨泓晔. All rights reserved.
//

#import "ZLImpressTableViewCell.h"
#import "ZLImpressCollectionViewCell.h"

@implementation ZLImpressTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    //头像
    self.avatar_lImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10*AUTO_WIDTH, 20*AUTO_HEIGHT, 50*AUTO_WIDTH, 50*AUTO_WIDTH)];
    [self.contentView addSubview:self.avatar_lImageView];
    self.avatar_lImageView.layer.masksToBounds = YES;
    self.avatar_lImageView.layer.cornerRadius = 25*AUTO_WIDTH;
    //    self.avatar_lImageView.backgroundColor = [UIColor redColor];
    //上面的name
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.avatar_lImageView.frame.origin.x + self.avatar_lImageView.frame.size.width + 10*AUTO_WIDTH, self.avatar_lImageView.frame.origin.y, 150*AUTO_WIDTH, 25*AUTO_HEIGHT)];
    //    self.nameLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.nameLabel];
    
    //下面的name
    self.nameTwoLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.size.height + self.nameLabel.frame.origin.y, self.nameLabel.frame.size.width + 120*AUTO_WIDTH, self.nameLabel.frame.size.height)];
    //    self.nameTwoLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.nameTwoLabel];
    
    //日期
    self.datetimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(260*AUTO_WIDTH, self.nameLabel.frame.origin.y, 110*AUTO_WIDTH, self.nameLabel.frame.size.height)];
    //    self.datetimeLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.datetimeLabel];
    
    //
    self.trip_textLabel = [[UILabel alloc]init];
    //    self.trip_textLabel.backgroundColor = [UIColor greenColor];
    self.trip_textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.trip_textLabel.numberOfLines = 0;
    [self.contentView addSubview:self.trip_textLabel];
    
#pragma mark - 创建UICollectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 5, 10, 5);
    flowLayout.minimumLineSpacing = 5*AUTO_WIDTH;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.myCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160*AUTO_HEIGHT) collectionViewLayout:flowLayout];
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.myCollectionView.backgroundColor = self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    
    [self.contentView addSubview:self.myCollectionView];
    
    [self.myCollectionView registerClass:[ZLImpressCollectionViewCell class] forCellWithReuseIdentifier:@"ZLImpressCollectionViewCell"];
}
#pragma mark - 重写set方法
- (void)setBigM:(ZLTravelsModel *)bigM
{
    self.trip_textLabel.frame = CGRectMake(self.avatar_lImageView.frame.origin.x, self.nameTwoLabel.frame.size.height + self.nameTwoLabel.frame.origin.y + 10, 355, bigM.height);
    self.trip_textLabel.text = bigM.trip_text;
    
    self.myCollectionView.frame = CGRectMake(0, bigM.height + 85, 375, 160);
    
    self.datetimeLabel.text = bigM.myTrip.datetime;
    self.nameTwoLabel.text = [@"@" stringByAppendingString:bigM.myTrip.name];
    self.nameLabel.text = bigM.myTrip.fuckM.name;
    
    [self.avatar_lImageView sd_setImageWithURL:[NSURL URLWithString:bigM.myTrip.fuckM.avatar_l] placeholderImage:nil];
    
    [self.myCollectionView reloadData];
}


#pragma mark - CollectionView Delegate && DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.cellArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ZLImpressCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZLImpressCollectionViewCell" forIndexPath:indexPath];
    ZLwaypointsModel *smaM = [self.cellArray objectAtIndex:indexPath.row];
    cell.smaM = smaM;
    
    
    
//    cell.imageWidth = self.imageWidth;
//    cell.imageHeight = self.imageHeight;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
//    self.imageWidth = [[[self.cellArray objectAtIndex:self.cellArray.count - 1] littleM] w];
//    self.imageHeight = [[[self.cellArray objectAtIndex:self.cellArray.count - 1] littleM] h];
    
    return CGSizeMake((375 - 25)/3, 140*AUTO_HEIGHT);
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
